package com.aaa.service.impl;

import com.aaa.entity.TblTestPlanSas;
import com.aaa.entity.TblTestPlanSds;
import com.aaa.dao.TblTestPlanSdsDao;
import com.aaa.service.TblTestPlanSdsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 测试计划fpa(TblTestPlanSds)表服务实现类
 *
 * @author makejava
 * @since 2022-07-17 15:48:04
 */
@Service("tblTestPlanSdsService")
public class TblTestPlanSdsServiceImpl implements TblTestPlanSdsService {
    @Resource
    private TblTestPlanSdsDao tblTestPlanSdsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TblTestPlanSds queryById(Integer id) {
        return this.tblTestPlanSdsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tblTestPlanSds 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<TblTestPlanSds> queryByPage(TblTestPlanSds tblTestPlanSds, PageRequest pageRequest) {
        long total = this.tblTestPlanSdsDao.count(tblTestPlanSds);
        return new PageImpl<>(this.tblTestPlanSdsDao.queryAllByLimit(tblTestPlanSds, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tblTestPlanSds 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(TblTestPlanSds tblTestPlanSds) {
        //随机生成六位数
        int random = (int) ((Math.random() * 9 + 1) * 100000);
        tblTestPlanSds.setTestCode(random);
        int insert = this.tblTestPlanSdsDao.insert(tblTestPlanSds);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    /**
     * 修改数据
     *
     * @param tblTestPlanSds 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(TblTestPlanSds tblTestPlanSds) {
        int update = this.tblTestPlanSdsDao.update(tblTestPlanSds);
        if (update > 0) {
            return true;
        }
        return false;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String idList) {
        return this.tblTestPlanSdsDao.deleteById(idList) > 0;
    }

    /**
     * @param tblTestPlanSds
     * @return boolean
     * @create by: feng (zhaixing@163.com)
     * @description: 查询计划名称是否重名
     * @create time: 2022/7/15 15:07
     */
    @Override
    public boolean repetitionName(TblTestPlanSds tblTestPlanSds) {
        Integer integer = this.tblTestPlanSdsDao.repetitionName(tblTestPlanSds);
        if (integer == 0) {
            return true;
        }
        return false;
    }
}
